const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const CheckIn = sequelize.define('CheckIn', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  check_date: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    comment: '打卡日期'
  },
  check_time: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '打卡时间'
  },
  study_duration: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '学习时长（分钟）'
  },
  mood: {
    type: DataTypes.ENUM('excellent', 'good', 'normal', 'tired', 'bad'),
    defaultValue: 'normal',
    comment: '学习状态'
  },
  summary: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '今日学习总结'
  },
  plan_tomorrow: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '明日学习计划'
  },
  completed_tasks: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '今日完成的任务列表'
  }
}, {
  tableName: 'checkin_records',
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'check_date']
    },
    {
      fields: ['check_date']
    }
  ]
});

module.exports = CheckIn; 